// NetSinkLib.h : main header file for the NETSINKLIB DLL
//

#if !defined(__NETSINKLIB_H__)
#define __NETSINKLIB_H__

#include <winsock2.h>

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

typedef enum
{
	NLERR_SUCCESS               =  0,
	NLERR_UNKNOWN_ERROR         = -301,
	NLERR_INVALID_LICENSE       = -302,
	NLERR_NOT_INIT              = -303,
	NLERR_REACH_MAX_SERVER_CNT  = -304,
	NLERR_REACH_MAX_CLIENT_CNT  = -305,
	NLERR_REACH_MAX_LISTEN_CNT  = -306,
	NLERR_REACH_MAX_UDP_CNT     = -307,
	NLERR_REACH_MAX_MULCAST_CNT = -308,
	NLERR_INVALID_SINK_ID       = -309,
	NLERR_SEND_BUF_FULL         = -310,
	NLERR_CONNECT_TIMEOUT       = -311,
	NLERR_INVALID_PARAMETER     = -312,
	NLERR_CAN_NOT_FIND_NET_CARD = -313,
	NLERR_INVALID_PORT_NUM      = -314,
}enNLErrCode;

typedef enum
{
	SINK_RESERVED,
	SINK_TO_TCP_CLIENT,  // Sink of Server.           1000 <= nSinkID < 2000   Max Client Count: 1000 , Max Listen Port Count: 32
	SINK_TO_TCP_SERVER,  // Sink of Client.           3000 <= nSinkID < 4000   Max Server Count: 1000
	SINK_TO_UDP_PORT,    // Sink to Local UDP Port.   5000 <= nSinkID < 5032   Max UDP Port Count: 32
	SINK_TO_MULTICAST,   // Sink of Multicast.        7000 <= nSinkID < 7032   Max Multicast Count(Sender+Recver): 32
}enSinkType;

#define BASE_ID_OF___SINK_TO_TCP_CLIENT     1000
#define BASE_ID_OF___SINK_TO_TCP_SERVER     3000
#define BASE_ID_OF___SINK_TO_UDP_PORT       5000
#define BASE_ID_OF___SINK_TO_MULTICAST      7000

typedef enum
{
	MULTYPE_SENDER,
	MULTYPE_RECEIVER
}enMulticastType;

typedef void (CALLBACK* ON_RECV_SINK_DATA)(enSinkType eSinkType, int nSinkID, LPBYTE pData,
										   DWORD dwSize, SOCKADDR_IN * pSrcAddr); // TCP & UDP & Multicast
typedef void (CALLBACK* ON_SINK_CLOSE)(enSinkType eSinkType, int nSinkID); // TCP
typedef BOOL (CALLBACK* ON_ACCEPT_CLIENT)(enSinkType eSinkType, int nSinkID,
										  SOCKADDR_IN * pClientAddr, UINT nListenPort); // TCP

int WINAPI NETLIB_AEBELL_License(LPCSTR pSerialNumber);
int WINAPI NETLIB_Init(ON_RECV_SINK_DATA OnRecv, ON_SINK_CLOSE OnClose, ON_ACCEPT_CLIENT OnAccept,
					   int nMaxSvrCnt, int nMaxCltCnt, int nMaxUdpCnt, int nMaxMulcastCnt, DWORD dwSendBufSize);
int WINAPI NETLIB_DeInit();
int WINAPI NETLIB_Listen(UINT nPort, LPCSTR pLocalIp); // TCP
int WINAPI NETLIB_UnListen(UINT nPort); // TCP
int WINAPI NETLIB_Connect(LPCSTR pServerIp, UINT nPort, int nTimeout, int * pSinkID); // TCP
int WINAPI NETLIB_Disconnect(int nSinkID); // TCP
int WINAPI NETLIB_BindUdp(UINT nPort, LPCSTR pLocalIp, int * pSinkID); // UDP
int WINAPI NETLIB_UnBindUdp(int nSinkID); // UDP
int WINAPI NETLIB_JoinMulcast(enMulticastType eMulcastType, LPCSTR pMulcastIp, UINT nMulcastPort, 
							  LPCSTR pLocalIp, int * pSinkID); // Multicast
int WINAPI NETLIB_LeaveMulcast(int nSinkID); // Multicast
int WINAPI NETLIB_Send(int nSinkID, LPBYTE pData, DWORD dwSize, SOCKADDR_IN * pDstAddr); // TCP & UDP & Multicast
int WINAPI NETLIB_GetSendBufSize(int nSinkID, DWORD * pSize);
int WINAPI NETLIB_GetSendPendingSize(int nSinkID, DWORD * pSize);
int WINAPI NETLIB_GetSinkType(int nSinkID, enSinkType * pSinkType);


#ifdef __cplusplus
} // End of extern "C" block
#endif // __cplusplus

#endif // !defined(__NETSINKLIB_H__)

